package com.moonshineproject.plugin.fullscreen
{
	import com.moonshineproject.plugin.IMenuPlugin;
	import com.moonshineproject.plugin.PluginBase;
	import com.moonshineproject.plugin.menu.vo.MenuItem;
	
	import flash.display.StageDisplayState;
	import flash.events.Event;
	
	import mx.core.FlexGlobals;

	public class FullscreenPlugin extends PluginBase implements IMenuPlugin
	{
		public static const EVENT_FULLSCREEN:String = "fullscreenEvent";
		
		override public function get name():String			{ return "Fullscreen Plugin"; }
		override public function get author():String		{ return "Moonshine Project Team"; }
		override public function get description():String	{ return "Show edit in fullscreen. Esc exits."; }
		
		override public function activate():void
		{
			super.activate();
			
			dispatcher.addEventListener(EVENT_FULLSCREEN, handleToggleFullscreen);
		}
		
		public function getMenu():MenuItem
		{
			// Since plugin will be activated if needed we can return null to block menu
			if( !_activated ) return null;
			
			var viewMenu:MenuItem = new MenuItem('View');
			viewMenu.parents = ["View"];
			viewMenu.items = new Vector.<MenuItem>();
			viewMenu.items.push(new MenuItem('Fullscreen', null, EVENT_FULLSCREEN));
			
			return viewMenu;
		}
		
		protected function handleToggleFullscreen(event:Event):void
		{
			var stage:Object = FlexGlobals.topLevelApplication.stage;
			if( stage.displayState == StageDisplayState.NORMAL ) 
			{
				stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
			} 
			else 
			{
				stage.displayState = StageDisplayState.NORMAL;
			}
		}
		
	}
}